﻿using AnQinFrameWorkAPI.Entity.BaseInfo.DTO.Staff;
using AnQinFrameWorkAPI.Entity.BaseInfo.View.Staff;
using AnQinFrameWorkAPI.Service.BaseInfo;
using FrameWork.Entity;
using Microsoft.AspNetCore.Mvc;

namespace AnQinFrameWorkAPI.Controllers.BaseInfo;

/// <summary>
///     员工API
/// </summary>
[Route("api/[controller]")]
[ApiController]
[ApiExplorerSettings(GroupName = "BaseInfo")]
public class StaffController : ControllerBase
{
    //业务接口
    private readonly StaffService _staffService;

    //构造注入
    public StaffController(StaffService staffService)
    {
        _staffService = staffService;
    }

    /// <summary>
    ///     获取员工列表
    /// </summary>
    [ProducesResponseType(typeof(StaffView), 200)]
    [HttpGet]
    public async Task<IActionResult> GetStaffList([FromQuery] StaffSearchDTO staffSearchDTO)
    {
        var response = await _staffService.GetStaffList(staffSearchDTO);
        return StatusCode(response.Status, response);
    }

    /// <summary>
    ///     新增人员
    /// </summary>
    /// <params name="staffAddDTO"></params>
    [HttpPost]
    public async Task<IActionResult> AddStaff([FromBody] StaffAddDTO staffAddDTO)
    {
        var response = await _staffService.AddStaff(staffAddDTO);
        return StatusCode(response.Status, response);
    }

    /// <summary>
    ///     编辑人员
    /// </summary>
    /// <params name="staffIUpdateDTO"></params>
    [HttpPut]
    public async Task<IActionResult> PutStaff([FromBody] StaffUpdateDTO staffIUpdateDTO)
    {
        var response = await _staffService.PutStaff(staffIUpdateDTO);
        return StatusCode(response.Status, response);
    }

    /// <summary>
    ///     删除人员
    /// </summary>
    [HttpDelete]
    public async Task<IActionResult> DeleteStaff([FromBody] SingleIdDTO deleteDTO)
    {
        var response = await _staffService.DeleteStaff(deleteDTO);
        return StatusCode(response.Status, response);
    }

    /// <summary>
    ///     批量删除人员
    /// </summary>
    [HttpDelete("DeleteMulti")]
    public async Task<IActionResult> DeleteArrayStaff([FromBody] IdArrayDTO idArrayDTO)
    {
        var response = await _staffService.DeleteArrayStaff(idArrayDTO);
        return StatusCode(response.Status, response);
    }
}